(function ($) {
	AjaxSolr.ExpressionWidget = AjaxSolr.AbstractWidget.extend({
		loader:null,
		expressions:null,
		colorData:null,
		column:-1,
		init: function(){
			var self=this;

			self.loader = new Biojs.ExpressionLoader({
				target: self.target
			});	
			self.loader.onFileLoaded(function( objEvent ) {
				self.expressions =objEvent.expressions;
				self.colorData=objEvent.colorData;
				self.column=objEvent.column;
				self.manager.widgets["graph"].registerStyler("expression",function () {self.paintProteins(self);});
				self.manager.widgets["graph"].executeStylers();
			}); 
			self.loader.onFileRemoved(function( objEvent ) {
				self.manager.widgets["graph"].removeStyler("expression");
				self.manager.widgets["graph"].executeStylers();
			}); 
			
		},
		afterRequest: function () {
			var self = this;
			self.manager.widgets["graph"].executeStylers();
		},
		paintProteins:function(self){
//			var self = this;
			if (self.loader==null || self.expressions==null) return;
			var proteins = self.manager.widgets["graph"].graph.proteins;
			for(var i=0; i<proteins.length; i++) {
				if( typeof self.expressions[proteins[i].id] != "undefined") {
					var value=1*self.expressions[proteins[i].id][self.column*1];
					var rgb = self.loader.getRGBString(value);
					self.manager.widgets["graph"].graph.setFillColor("[id =figure_"+proteins[i].id+"]",rgb);
				}
			}			
			self.manager.widgets["graph"].graph.restart();
		}
	});
})(jQuery);